package com.lss.cloud.controller;


import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import com.lss.cloud.Resp.ResultData;
import com.lss.cloud.Resp.ReturnCodeEnum;
import com.lss.cloud.apis.PayFeginApi;
import com.lss.cloud.entities.PayDTO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

/**
 * 2024/3/14-21:11
 * 功能:
 */
@RestController
@Slf4j
public class OrderController {
    @Resource
    private PayFeginApi payFeginApi;

    @PostMapping("fegin/add/pay")
    public ResultData addOrder(@RequestBody PayDTO payDTO) {
        System.out.println("第一步：模拟本地addOrder新增订单成功(省略sql操作)，第二步：再开启addPay支付微服务远程调用");
        ResultData resultData = payFeginApi.addPay(payDTO);
        return resultData;
    }

    @GetMapping("fegin/get/pay/{id}")
    public ResultData getOrderById(@PathVariable("id") Integer id) {
        System.out.println("-------支付微服务远程调用，按照id查询订单支付流水信息");
        ResultData payById=null;
        try {
            System.out.println("DateTime.now() = " + DateTime.now());
            payById = payFeginApi.getPayById(id);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("e.getMessage() = " + e.getMessage());
            System.out.println("DateTime.now() = " + DateTime.now());
        }

        return payById;
    }

    /**
     * 测试 负载均衡。
     *
     * @return
     */
    @GetMapping("fegin/get/info")
    public String getInfo() {
        String info = payFeginApi.getInfo();
        return info;
    }

}
